package com.shop.loan.proxy;

import com.shop.loan.model.view.LoanOrderByPartPay;
import com.shop.loan.util.LoanOrderUtil;
import org.springframework.stereotype.Service;
import xyz.erupt.annotation.fun.DataProxy;
import xyz.erupt.annotation.model.Row;
import xyz.erupt.annotation.query.Condition;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@Service
public class LoanOrderByPartMoneyProxy implements DataProxy<LoanOrderByPartPay> {

    @Resource
    LoanOrderUtil loanOrderUtil;


    @Override
    public String beforeFetch(List<Condition> conditions) {
        conditions.clear();
        return null;
    }

    @Override
    public void afterFetch(Collection<Map<String, Object>> list) {
        list.clear();
        loanOrderUtil.searchPartOrderList(list);
        //列表显示字段完善
        loanOrderUtil.updateShowDayList(list);
    }

    @Override
    public List<Row> extraRow(List<Condition> conditions) {
        String sql = "ord.status = 7 and (bill.pay_money > 0 or bill.pay_money_by_guarantee > 0) and bill.pay_status = false";
        return loanOrderUtil.setOrderListSumRow(sql);
    }


//    @Override
//    public String beforeFetch(List<Condition> conditions) {
//        return loanOrderUtil.getOrderListBeforeFetch("LoanOrderByPartPay", conditions);
//    }
//
//    @Override
//    public void afterFetch(Collection<Map<String, Object>> list) {
//        loanOrderUtil.setOrderListData(list);
//    }
//
//    @Override
//    public List<Row> extraRow(List<Condition> conditions) {
//        String sqlEx = loanOrderUtil.getOrderListBeforeFetchByMybatis("ord");
//        if (!StringUtils.hasText(sqlEx)) {
//            sqlEx = "ord.pay_money > 0 and ord.status = " + OrderStatus.underway.getStatus();
//        } else {
//            sqlEx = sqlEx + " and ord.pay_money > 0 and ord.status = " + OrderStatus.underway.getStatus();
//        }
//        return loanOrderUtil.setOrderListSumRow(sqlEx);
//    }
}
